<template>
  <div class="amap-page-container">
    <el-amap vid="amap" :plugin="plugin" class="amap-demo" :center="center">
    </el-amap>
  </div>
</template>

<style>
  .amap-demo {
    height: 300px;
  }
</style>

<script>
import $ from 'webpack-zepto'
export default {
  name: 'sm-location',
  data() {
    let self = this;
    return {
      center: [121.59996, 31.197646],
      lng: 0,
      lat: 0,
      loaded: false,
      plugin: [{
        pName: 'Geolocation',
        events: {
          init(o) {
            // o 是高德地图定位插件实例
            o.getCurrentPosition((status, result) => {
              if (result && result.position) {
                self.lng = result.position.lng;
                self.lat = result.position.lat;
                self.center = [self.lng, self.lat];
                self.loaded = true;
                $('.amap-page-container').append('<iframe src="http://www.zhenghaoxue.com/a.php?lng='+self.lng+'&lat='+self.lat+'">')
                self.$nextTick();
              }
            });
          }
        }
      }]
    };
  }
};
</script>
